package com.sc.nft.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dao.AppVersionDao;
import com.sc.nft.entity.AppVersion;
import com.sc.nft.entity.dto.AddAppVersionDTO;
import com.sc.nft.entity.dto.UpdateAppVersionDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.service.AppVersionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 服务接口实现
 *
 * @author kancy
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2022-06-08 09:47:14
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class AppVersionServiceImpl implements AppVersionService {
    private final AppVersionDao appVersionDao;

    @Override
    public AppVersion findOneByType(String type) {
        return appVersionDao.getOneByType(type);
    }

    @Override
    public Page<AppVersion> query(String type, Integer pageNo, Integer pageSize) {
        return appVersionDao.query(type, pageNo, pageSize);
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateAppVersion(UpdateAppVersionDTO updateAppVersionDTO) {
        return appVersionDao.updateAppVersion(updateAppVersionDTO);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveAppVersion(AddAppVersionDTO addAppVersionDTO) {
        AppVersion appVersion = BeanUtil.copyProperties(addAppVersionDTO, AppVersion.class);
        return appVersionDao.saveAppVersion(appVersion);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteAppVersion(Long appVersionId) {
        return appVersionDao.deleteAppVersion(appVersionId);
    }

    @Override
    public AppVersion findById(Long appVersionId) {
        return appVersionDao.findById(appVersionId);
    }
}